package walker

import (
	"fmt"
	"os"
	"path"
)

var jobs []*site
var othersIds map[string]int

func StartWalk(startpath string) {
	othersIds = make(map[string]int)

	dir := path.Dir(startpath)
	os.Chdir(dir) // cd 到 videos的上级目录

	videosdir := path.Base(startpath)

	st := NewSite(1, "Home", "homeSource", videosdir)
	jobs = append(jobs, st)

	// site == 1 是默认
	//   其他 site >1
	//   subgroup 属于 site 0
	st.JustDoIt_Walk() //遍历
}

func Save() {
	for i, st := range jobs {
		fmt.Printf("[i] site:%v\n", i)

		st.Save(nil)

		// saveGroups(st.Groups, uint(st.ID), ids)

		// for j, g := range st.Groups {
		// 	fmt.Printf("site:%v:group%v\n", i, j)
		// 	fmt.Printf("group.Name: %v\n", g.Name)
		// 	for k, vod := range g.Vods {
		// 		fmt.Printf("k: %v\n", k)
		// 		fmt.Printf("vod.Dir: %v\n", vod.Dir)
		// 		fmt.Printf("vod.Name: %v\n", vod.Name)
		// 		fmt.Printf("len(vod.VideoPaths): %v\n", len(vod.VideoPaths))
		// 		fmt.Printf("vod.InfoJsonPath: %v\n", vod.InfoJsonPath)
		// 		fmt.Printf("vod.Pic: %v\n", vod.Pic)
		// 	}
		// 	g.SubGroups
		// }

	}
}

func Finish() {
	finishLogging()
}
